package com.tg.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.tg.app.R;
import com.appbase.custom.base.SettingData;

import java.util.ArrayList;

public class SetNameAdapter extends BaseAdapter {
    private ArrayList<SettingData> list;
    private Context context;
    private boolean isCheckButton  = true;
    private  int iconRes =0;
    public SetNameAdapter(ArrayList<SettingData> list, Context context){
        this.list = list;
        this.context = context;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    public void setCheckButton(boolean checkButton) {
        isCheckButton = checkButton;
    }

    public void setIconImageResource(int iconRes) {
        this.iconRes = iconRes;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.set_name_item,null);
            holder.item = convertView.findViewById(R.id.item_resolution);
            holder.icon = convertView.findViewById(R.id.imageButton2);
            holder.divider = convertView.findViewById(R.id.split_line);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();

        }

        if (position == 0) {
            convertView.setBackgroundResource(R.drawable.white_rounded_bg_part_top);
            holder.divider.setVisibility(View.VISIBLE);
        } else if (position == list.size() - 1) {
            convertView.setBackgroundResource(R.drawable.white_rounded_bg_part_bottom);
            holder.divider.setVisibility(View.GONE);
        } else {
            convertView.setBackgroundResource(R.drawable.white_rounded_bg_part_middle);
            holder.divider.setVisibility(View.VISIBLE);
        }

      SettingData data = list.get(position);
        holder.item.setText(data.getName());
        if (isCheckButton){
            if(data.getFlag() == 1){
                holder.icon.setImageResource(R.mipmap.icon_device_ap_set_name_selected);
            }else{
                holder.icon.setImageResource(R.mipmap.icon_device_ap_set_name_normal);
            }

        }
        return convertView;
    }

    public final class ViewHolder
    {
        public TextView item;
        public ImageView icon;
        public View divider;
    }

}
